<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!--查询条件设置-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务名称">
              <a-input placeholder="请输入jobName"
                       v-model="queryParam.jobName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否为系统任务">
              <j-dict-select-tag
                v-model="queryParam.jobType"
                dictCode="yn"
                placeholder="请选择jobType"></j-dict-select-tag>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务是否开启">
              <j-dict-select-tag
                v-model="queryParam.isenable"
                dictCode="yn"
                placeholder="请选择isenable"></j-dict-select-tag>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否记录任务日志">
              <j-dict-select-tag
                v-model="queryParam.recordLog"
                dictCode="yn"
                placeholder="请选择recordLog"></j-dict-select-tag>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button class="ant-btn-custom" @click="searchQuery" icon="search">查询</a-button>
      <a-button class="ant-btn-custom" @click="searchReset" icon="reload">重置</a-button>
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" @click="importExcel" icon="import">导入</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('定时任务配置.xlsx')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
                    <span slot="action" slot-scope="text, record">

                          <a @click="handleEdit(record)">编辑</a>
                          <a-divider type="vertical"/>
                          <a-dropdown>
                            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
                            <a-menu slot="overlay">
                              <a-menu-item>
                                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                                  <a>删除</a>
                                </a-popconfirm>
                              </a-menu-item>
                            </a-menu>
                          </a-dropdown>
                        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <SysTaskJobModal ref="modalForm" @ok="modalFormOk"></SysTaskJobModal>
    <common-import-modal ref="commonImportModal" :templateUrl="this.url.templateExcel"
                         :importUrl="this.url.importXlsUrl" templateFileName="定时任务配置.xlsx"
                         @ok="modalFormOk"></common-import-modal>
  </a-card>
</template>

<script>
import SysTaskJobModal from '../modules/SysTaskJobModal'
import CommonImportModal from '@/components/excel/CommonImportModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'SysTaskJobList',
  mixins: [JeecgListMixin],
  components: {
    SysTaskJobModal,
    CommonImportModal
  },
  data() {
    return {
      description: '定时任务配置管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          align: 'center',
          sorter: false,
          title: '任务组',
          width: 200,
          ellipsis: true,
          dataIndex: 'jobGroup',
        },
        {
          align: 'center',
          sorter: false,
          title: '任务名称',
          width: 200,
          ellipsis: true,
          dataIndex: 'jobName',
        },
        {
          align: 'center',
          sorter: false,
          title: '是否为系统任务',
          width: 200,
          ellipsis: true,
          dataIndex: 'jobType_dictText',
        },
        {
          align: 'center',
          sorter: false,
          title: '创建人',
          width: 200,
          ellipsis: true,
          dataIndex: 'createBy',
        },
        {
          align: 'center',
          sorter: false,
          title: '更新时间',
          width: 200,
          ellipsis: true,
          dataIndex: 'updateTime',
        },
        {
          align: 'center',
          sorter: false,
          title: '任务执行类',
          width: 200,
          ellipsis: true,
          dataIndex: 'jobClass',
        },
        {
          align: 'center',
          sorter: false,
          title: '任务表达式',
          width: 200,
          ellipsis: true,
          dataIndex: 'jobCronexpression',
        },
        {
          align: 'center',
          sorter: false,
          title: '任务是否开启',
          width: 200,
          ellipsis: true,
          dataIndex: 'isenable_dictText',
        },
        {
          align: 'center',
          sorter: false,
          title: '更新人',
          width: 200,
          ellipsis: true,
          dataIndex: 'updateBy',
        },
        {
          align: 'center',
          sorter: false,
          title: '任务唯一ID',
          width: 200,
          ellipsis: true,
          dataIndex: 'jobId',
        },
        {
          align: 'center',
          sorter: false,
          title: '主键',
          width: 200,
          ellipsis: true,
          dataIndex: 'id',
        },
        {
          align: 'center',
          sorter: false,
          title: '执行任务参数',
          width: 200,
          ellipsis: true,
          dataIndex: 'parameter',
        },
        {
          align: 'center',
          sorter: false,
          title: '是否记录任务日志',
          width: 200,
          ellipsis: true,
          dataIndex: 'recordLog_dictText',
        },
        {
          align: 'center',
          sorter: true,
          title: '创建时间',
          width: 200,
          ellipsis: true,
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'action' },
        }
      ],
      url: {
        list: '/taskjob/SysTaskJob/list',
        delete: '/taskjob/SysTaskJob/delete',
        importXlsUrl: '/taskjob/SysTaskJob/importExcel',
        exportXlsUrl: '/taskjob/SysTaskJob/exportExcel',
        templateExcel: '/taskjob/SysTaskJob/getExcelTemplate',
      },
    }
  },
  created() {
    this.isorter = {
      column: 'createTime',
      order: 'desc',
    }
  },
  computed: {},
  methods: {
    importExcel() {
      this.$refs.commonImportModal.show()
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
